﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AMS.DD35.DbAccess.SqlClient
{
    public class SqlEDMStaticLookupConnector : IStaticLookupConnector
    {
        public Dictionary<int, string> GetRaces()
        {
            Dictionary<int, string> results = new Dictionary<int, string>();

            using (DD35DataEntities dbContext = new DD35DataEntities())
            {
                foreach (Race race in dbContext.Races)
                {
                    results.Add(race.Race_ID, race.Race_Name);
                }
            }

            return results;
        }

        public Dictionary<int, string> GetDeities()
        {
            Dictionary<int, string> results = new Dictionary<int, string>();

            using (DD35DataEntities dbContext = new DD35DataEntities())
            {
                foreach (Deity deity in dbContext.Deities)
                {
                    results.Add(deity.Deity_ID, deity.Deity_Name);
                }
            }

            return results;
        }

        public Dictionary<int, string> GetFeats()
        {
            Dictionary<int, string> results = new Dictionary<int, string>();

            using (DD35DataEntities dbContext = new DD35DataEntities())
            {
                foreach (Feat feat in dbContext.Feats)
                {
                    results.Add(feat.Feat_ID, feat.Feat_Name);
                }
            }

            return results;
        }

        public Dictionary<int, string> GetSkills()
        {
            Dictionary<int, string> results = new Dictionary<int, string>();

            using (DD35DataEntities dbContext = new DD35DataEntities())
            {
                foreach (Skill skill in dbContext.Skills)
                {
                    results.Add(skill.Skill_ID, skill.Skill_Name);
                }
            }

            return results;
        }

        public Dictionary<string, string> GetClasses()
        {
            Dictionary<string, string> results = new Dictionary<string, string>();

            using (DD35DataEntities dbContext = new DD35DataEntities())
            {
                foreach (Class cl in dbContext.Classes)
                {
                    // TODO: convert Class_ID in DB from int16 to string (3 letter abbreviation)
                    results.Add(cl.Class_ID.ToString(), cl.Class_Name);
                }
            }

            return results;
        }

        public Dictionary<long, string> GetCharacters(string userId)
        {
            Dictionary<long, string> results = new Dictionary<long, string>();

            using (DD35DataEntities dbContext = new DD35DataEntities())
            {
                //IEnumerable<Character> results = dbContext.Characters.SelectMany(c => c.Username.ToLower() == userId.ToLower());
                foreach (Character ch in dbContext.Characters)
                {
                    if (ch.Username.ToLower() == userId.ToLower())
                        results.Add(ch.Character_ID, ch.Character_Name);
                }
            }

            return results;
        }
    }
}
